
    <div>
        <i class="layui-icon layui-icon-set"></i>
        <span>流程定义节点人员设置</span>
        <div class="layui-btn-container" style="display: inline-block;margin-left: 5px;">
            <a class="layui-btn layui-btn-sm" href="javascript:;" id="setUser">
                <span>快捷设置</span>
            </a>
        </div>
    </div>
    <#list nodeUserMapList as nodeUserMap>
    <div class="layui-card">
        <div class="layui-card-header">
            <div style="float: left;">${nodeUserMap.nodeName}(${nodeUserMap.nodeId})</div>
            <div style="float: right">
                <a class="layui-btn layui-btn-xs addButton"  id="add_${nodeUserMap.nodeId}"><span>添加</span></a>
                <a class="layui-btn layui-btn-xs updButton" id="upd_${nodeUserMap.nodeId}">修改</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger delButton"  id="del_${nodeUserMap.nodeId}">删除</a>
                <a class="layui-btn layui-btn-xs saveButton" id="save_${nodeUserMap.nodeId}">保存批次号</a>
            </div>
        </div>
        <div class="layui-card-body">
            <table class="layui-table" id="table_${nodeUserMap.nodeId}">
                <thead>
                <tr>
                    <th style="width:10%">序号</th>
                    <th style="width:80%">条件</th>
                    <th style="width:10%">批次号</th>
                </tr>
                </thead>
                <tbody>
                <input type="hidden" name="setId" value="${nodeUserMap.setId}"/>
                <input type="hidden" name="modelId" value="${modelId}"/>
                <input type="hidden" name="nodeId" value="${nodeUserMap.nodeId}"/>
                <#if (nodeUserMap.bpmUserConditionList?size > 0)>
                <#list nodeUserMap.bpmUserConditionList as conditionNode>
                <tr>
                    <td>
                        <input type="radio" name="radio_${nodeUserMap.nodeId}}">${conditionNode_index?if_exists+1}
                        <input type="hidden" name="conditionId" value="${conditionNode.id}"/>
                        <input type="hidden" name="sn" value="${conditionNode.sn}"/>
                    </td>
                    <td >
                        <#--规则描述-->
                        <div name="condition" >
                            <textarea style="display:none;">${conditionNode.condition}</textarea>
                            <label></label>
                        </div>
                        <#--人员描述-->
                        <label>${conditionNode.conditionShow}</label>
                    </td>
                    <td><input name="groupNo" style="width:70px;" type="text" value="${conditionNode.groupNo}"></td>
                </tr>
                </#list>
            </#if>
            </tbody>
            </table>
        </div>
    </div>
    </#list>
    <!--todo 三个及以上个 弹窗时启用的-->
    <div id="windowUrls" style="display: none"></div>

    <script>
        layui.use(['table','setter','element','util'], function () {
            var setter=layui.setter
                ,element = layui.element
                ,$ = layui.$
                ,commons = layui.commons
                ,util = layui.util;
            var modelId = '${modelId}';
            var parentProcDefId = '${parentProcDefId}';
            //全局使用。即所有弹出层都默认采用，但是单个配置skin的优先级更高
            layer.config({
                skin: 'btn-class'
            });
            //人员初始化显示
            $("[name='condition']").each(function () {
                //规则显示，获取condition
                var condition = $("textarea",this).val();
                if(!condition){
                    return false;
                }
                //转换为JSON
                var conditionArr = JSON.parse(condition);
                //转换为数组
                var conditionShow ="";
                for(var i=0;i<conditionArr.length;i++) {
                    var _json = conditionArr[i];
                    if(i!=0) {
                        if (_json.compType == "and") {
                            conditionShow += " 并且 "
                        } else if (_json.compType == "or") {
                            conditionShow += " 或者 "
                        };
                    }
                    conditionShow += _json.conDesc;
                }
                //添加规则设置的内容
                $("label",this).html(conditionShow);

            });
            //快捷人员设置
            $('#setUser').click(function () {
                layer.open({
                    title:'快捷人员设置',
                    type: 2,
                    shade: 0.3,
                    area: ['800px', '500px'],
                    content: serverPath.workflowPath + setter.workflowLinkPath +'actDefModel/view/userSetQuickly?modelId='+modelId + "&parentProcDefId=" + parentProcDefId,
                    end: function(layero, index){
                        element.tabChange('commonSetting', "userSet");
                    }
                });
            });
            //删除
            $('.delButton').click(function () {
                var buttonId = this.id;
                var nodeId = buttonId.split("_")[1];
                var tableObj=$('#table_'+nodeId);
                var deleteObjs = $('input[type=radio]:checked',tableObj);
                if(deleteObjs.length==0){
                    layer.alert('请选择要删除的记录!');
                    return ;
                }else{
                    layer.confirm('确定删除吗？',{title:'提示'}, function(index) {
                        for(var i=deleteObjs.length-1;i>=0;i--){
                            var conditionIds=$(deleteObjs[i]).next('input[name="conditionId"]').val();
                            if(conditionIds!='' && conditionIds!=undefined){
                                $.ajax({
                                    type:"post",
                                    dataType:"json",
                                    url : serverPath.workflowPath + "/workflow/bpmUserCondition/del",
                                    data : {'conditionIds':conditionIds},
                                    success: function (result) {
                                        layer.msg(result.msg,{icon: 1,time:1000});
                                    }
                                })
                            }
                            $(deleteObjs[i]).parent().parent().fadeOut(500, function() {
                                $(this).remove();
                            });
                        }
                        layer.close(index);
                    });
                }
            });
            //添加
            $('.addButton').click(function () {
                var nodeId = this.id.split("_")[1];
                var windowUrl = 'actDefModel/view/userSetUpdate?modelId='+modelId+'&&nodeId='+nodeId+'&&parentProcDefId=${parentProcDefId}';
                parent.layer.open({
                    title:'配置节点人员',
                    type: 2,
                    shade: 0.3,
                    area: ['1044px', '650px'],
                    skin: 'btn-class',
                    btn:["保存","关闭"],
                    content: serverPath.workflowPath + setter.workflowLinkPath +windowUrl,
                    end: function(layero, index){
                        element.tabChange('commonSetting', "userSet");
                    },
                    yes:function (index,layero) {
                        var zx = 0
                        //获取iframe的body元素
                        var body = parent.layer.getChildFrame('body',index);
                        //得到iframe页的窗口对象
                        var iframeWin = parent.window[layero.find('iframe')[0]['name']];
                        // var iframeWin = $(window.parent.document).contents().find("iframe")[0].contentWindow;
                        // var iframeWin = $(layero).contents().find("iframe")[0].contentWindow;
                        // debugger
                        //执行iframe页的showMsg方法
                        // iframeWin.showMsg("mercy");
                        $.each(body.find('#tbodyUserSet tr'),function (key,val) {
                            if ($(val).find('select[name=assignType]').val()!='startUser') {
                                if ($(val).find('textarea[name=cmpNames]').val()=="") {
                                    parent.layer.msg("请输入有效参数",{icon:0,time:1000});
                                    zx = 1;
                                }
                            }
                        })
                        function closeUser() {
                            parent.layer.close(index); //如果设定了yes回调，需进行手工关闭
                        }
                        if (zx==0){
                            iframeWin.save(closeUser);
                        }


                    }
                });
            });
            //修改
            $('.updButton').click(function () {
                var nodeId = this.id.split("_")[1];
                var tableObj  = '#table_'+nodeId;
                var tabObjs = $('input[type="radio"]:checked',tableObj);
                var conditionId=$(tabObjs).next('input[name="conditionId"]').val();
                //是否被选中
                if(tabObjs.length==0){
                    layer.alert('请选择一条要修改的记录!');
                    return ;
                }
                //打开弹窗传值过去
                parent.layer.open({
                    title:'修改节点人员',
                    type:2,
                    shade:0.3,
                    btn:["保存","关闭"],
                    skin: 'btn-class',
                    area:  ['1000px', '650px'],
                    content:serverPath.workflowPath + setter.workflowLinkPath +"actDefModel/view/userSetUpdate?modelId="+modelId+"&&nodeId="+nodeId+"&&parentProcDefId=${parentProcDefId}&&conditionId="+conditionId,
                    end: function(layero, index){
                        element.tabChange('commonSetting', "userSet");
                    },
                    yes:function (index,layero) {
                        //获取iframe的body元素
                        var body = layer.getChildFrame('body',index);
                        //得到iframe页的窗口对象
                        var iframeWin = parent.window[layero.find('iframe')[0]['name']];
                        //执行iframe页的showMsg方法
                        // iframeWin.showMsg("mercy");

                        function closeUser() {
                            parent.layer.close(index); //如果设定了yes回调，需进行手工关闭
                        }
                        iframeWin.save(closeUser);
                    }
                });
            });
            //保存批次号
            $('.saveButton').on('click', function () {
                var conditionIds = [];
                var groupNos = [];
                var nodeId = this.id.split("_")[1];
                var tableObj=$('#table_'+nodeId);

                $('input[name=groupNo]',tableObj).each(function () {
                    var _this = $(this);
                    if( _this.val()!=_this.attr('value')){
                        var groupNo = _this.val();
                        var tr = _this.closest("tr");
                        var conditionId = $('input[name=conditionId]',tr).val();
                        conditionIds.push(conditionId);
                        groupNos.push(groupNo);
                    }
                });

                if(conditionIds.length == 0){ return; }
                $.ajax({
                    url: "${ctx}/workflow/bpmUserCondition/updateGroup"
                    ,method:'post'
                    , data: {'conditionIds': conditionIds.join(","), 'groupNos': groupNos.join(",")}
                    , dataType: 'json'
                    , success: function (res) {
                        if (commons._filterRecord(res)) {
                            layer.msg(res.msg, {icon: 6});
                        } else {
                            layer.msg(res.msg, {icon: 5});
                        }
                    }
                });
            });
        });
    </script>
